/* $RCSFile: CrmLocalizerManager.ascx.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/AddonNice/PageModules/CrmLocalizerManager/CrmLocalizerManager.ascx.cs $
 * $log$
 * Revision 20 2010/08/09 10:51:20  christian.surieux
 *   Added Log comment to all .aspx .ascx .master files
 * Revision 19 2010/08/09 09:43:50  christian.surieux
 *   Added Log to cs sources files
 * Revision 6 2010/08/06 19:56:24  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Data;
using System.Data.Common;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Globalization;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Diagnostics;
using System.Data.SqlClient;
using System.Web.Services.Protocols;

using AddonNice.UI;
using AddonNice.Design;
using AddonNice.UI.WebControls;
using AddonNice.Security;
using AddonNice.UI.DataTypes;
using AddonNice.Configuration;
using AddonNice.Configuration.Settings;
using AddonNice.Diagnostics;
using AddonNice.Helpers;
using AddonNice.Settings;
using AddonNice.Authentication;

using AddonNice.CRMWrapper;
using AddonNice.CRMWrapper.Design;

using Telerik.Web.UI;

using Trace2    =   System.Diagnostics.Trace;

namespace AddonNice.PageModules.CrmLocalizerManager 
{

 	#region Local TraceSwitch 
	public class CrmLocManagerTrace : ADNTraceSwitch
	{
		static public ADNTraceSwitch	Sw	            =	new ADNTraceSwitch("CrmLocManagerTrace","Special Trace Switch for CrmLocalizerManager");
	}
	#endregion Local TraceSwitch 

    #region const strings
    public class LStr
    {
        public const string CrmLocalizerManagerMemoLen  =	"MODULE_SETTINGS_FIELD_LOC_MEMOLEN";
        public const string CrmLocalizerManagerTextLen  =	"MODULE_SETTINGS_FIELD_LOC_TEXTLEN";
        public const string CrmLocalizerManagerMemoSize =	"MODULE_SETTINGS_FIELD_LOC_MEMOSIZE";
        public const string CrmLocalizerManagerTextSize =	"MODULE_SETTINGS_FIELD_LOC_TEXTSIZE";
        public const string UnableInsertAtt             =	"CRMLOCALIZER_UNABLE_INSERT_ATT";
        public const string AttributeInserted           =   "CRMLOCALIZER_ATT_INSERTED";
        public const string UnableDeleteAtt             =   "CRMLOCALIZER_UNABLE_DELETE_ATT";
        public const string All                         =   "CRMLOCALIZER_ALL";
        public const string UnableUpdateLoc             =   "CRMLOCALIZER_UNABLE_UPD_LOC";
        public const string LocUpdated                  =   "CRMLOCALIZER_LOC_UPDATED";
        public const string UnableDeleteLoc             =   "CRMLOCALIZER_UNABLE_DEL_LOC";
    }
    #endregion const strings
    
    
    /// <summary>
    /// Initializer class for CrmLocalizerManager 
    /// </summary>
    public class CrmLocalizerManagerSI : PortalCRMModuleControlSI
    {
        public CrmLocalizerManagerSI(ModuleSettingsDictionary bSettings,ISettingsOwner pm) : base()
        {
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]CrmLocalizerManagerSI Ctor BEG.",ModuleTraceSwitch.Sw.Info);
            InitSettings(bSettings,pm);
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]CrmLocalizerManagerSI Ctor END.",ModuleTraceSwitch.Sw.Info);
        }
 
        public override void InitSettings(ModuleSettingsDictionary bSettings,ISettingsOwner pm)
        {             
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]CrmLocalizerManagerSI InitSettings BEG.",ModuleTraceSwitch.Sw.Info);
            
            base.InitSettings(bSettings,pm);

            string extgrp                                   =   pm.ExtendedResourcesGroup;
            

            SettingItemSpecial CrmLocalizerManagerMemoLen   =   new SettingItemSpecial(LStr.CrmLocalizerManagerMemoLen,new IntegerDataType());
			CrmLocalizerManagerMemoLen.Order			    =	40;
            CrmLocalizerManagerMemoLen.ExtendedGroupName    =   extgrp;
            CrmLocalizerManagerMemoLen.Group                =   SettingItemGroup.MODULE_SPECIAL_SETTINGS;
            CrmLocalizerManagerMemoLen.Value			    =	"0"; // default value
			CrmLocalizerManagerMemoLen.Description		    =	"Value to limit the Memo field length, zero means no limit.";
            CrmLocalizerManagerMemoLen.EnglishName		    =	"Memo field length";
			bSettings.AddSetting(CrmLocalizerManagerMemoLen);

            SettingItemSpecial CrmLocalizerManagerMemoSize  =   new SettingItemSpecial(LStr.CrmLocalizerManagerMemoSize,new UnitDataType());
			CrmLocalizerManagerMemoSize.Order			    =	50;
            CrmLocalizerManagerMemoSize.ExtendedGroupName   =   extgrp;
            CrmLocalizerManagerMemoSize.Group               =   SettingItemGroup.MODULE_SPECIAL_SETTINGS;
            CrmLocalizerManagerMemoSize.Value			    =	"800px"; // default value
			CrmLocalizerManagerMemoSize.Description		    =	"Display width in pixel for Memo fields";
            CrmLocalizerManagerMemoSize.EnglishName		    =	"Memo field display width";
			bSettings.AddSetting(CrmLocalizerManagerMemoSize);

            SettingItemSpecial CrmLocalizerManagerTextLen   =   new SettingItemSpecial(LStr.CrmLocalizerManagerTextLen,new IntegerDataType());
			CrmLocalizerManagerTextLen.Order			    =	60;
            CrmLocalizerManagerTextLen.ExtendedGroupName    =   extgrp;
            CrmLocalizerManagerTextLen.Group                =   SettingItemGroup.MODULE_SPECIAL_SETTINGS;
            CrmLocalizerManagerTextLen.Value			    =	"0"; // default value
			CrmLocalizerManagerTextLen.Description		    =	"Value to limit the Text field length, zero means no limit.";
            CrmLocalizerManagerTextLen.EnglishName		    =	"Text field length";
			bSettings.AddSetting(CrmLocalizerManagerTextLen);

            SettingItemSpecial CrmLocalizerManagerTextSize  =   new SettingItemSpecial(LStr.CrmLocalizerManagerTextSize,new UnitDataType());
			CrmLocalizerManagerTextSize.Order			    =	70;
            CrmLocalizerManagerTextSize.ExtendedGroupName   =   extgrp;
            CrmLocalizerManagerTextSize.Group               =   SettingItemGroup.MODULE_SPECIAL_SETTINGS;
            CrmLocalizerManagerTextSize.Value			    =	"400px"; // default value
			CrmLocalizerManagerTextSize.Description		    =	"Display width in pixel for Text fields";
            CrmLocalizerManagerTextSize.EnglishName		    =	"Text field display width";
			bSettings.AddSetting(CrmLocalizerManagerTextSize);

            if ( CrmLocManagerTrace.Sw.TraceVerbose || ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine("[V]CrmLocalizerManagerSI InitSettings END",(CrmLocManagerTrace.Sw.TraceVerbose) ? CrmLocManagerTrace.Sw.Info:ModuleTraceSwitch.Sw.Info);
        }
    }

    /// <summary>
    ///	CrmLocalizerManager display prospects in a RadGrid.
    /// </summary>
	public partial class CrmLocalizerManager : PortalCRMModuleControl
    {
 		#region General implementation

        public override bool AdminModule
        {
            get
            {
                return true;
            }
        }

        /// <summary>
		/// AddonNice module key
		/// </summary>
		public override Guid GuidID
        {
            get
            {
                return new Guid("{1746298B-ABD5-4d76-873F-C589202A0955}");
            }
        }
		#endregion General implementation

        #region local Properties


        SortedList<CRMFieldDescListKey,CRMLocFieldDesc> Vals    =   new SortedList<CRMFieldDescListKey,CRMLocFieldDesc>();
        FieldLocalizerDB fDB                                    =   new FieldLocalizerDB();
        DynEntity currentDyn                                    =   null;
        const string strLocEntity                               =   "LocEntity";
        ArrayList _AllEntities  =   null;
        ArrayList GetAllEntities()
        {
            if (_AllEntities == null)
            {
                _AllEntities                                    =   MetadataCache.GetAllEntities(Wrapper,true);
            }
            return _AllEntities;
        }
        
        /// <summary>
        /// Get the Entity Config to build the attributes table
        /// </summary>
        EntityConfig _TConfig                                   =   null;
        string _entityName                                      =   string.Empty; //small caching
        public EntityConfig GetEntityConfig(string entityName)
        {
            if (_TConfig == null || 
                (_TConfig.entityFlags != EntityInternalItems.All) || 
                ( !_TConfig.isAdmin ) || 
                (_entityName != entityName) )
            {
                _TConfig                                        =   new EntityConfig(Wrapper,entityName);
                _entityName                                     =   entityName;
                if ( CrmLocManagerTrace.Sw.TraceVerbose )
                    Trace2.WriteLine(
                    string.Format("[V]CrmLocalizerManager GetEntityConfig created entityName: {0}, vflag: [{1}], isAdmin: {2}, DisplayMask: [{3}] ",
                    new object[] {entityName,_TConfig.entityFlags, true, _TConfig.DisplayMask }),CrmLocManagerTrace.Sw.Info);
            }
            return _TConfig;
        }

        #endregion local Properties

        #region Ctor and Initializer

        /// <summary>
        /// Ctor allows settings to select an entity and its fields to localize
        /// </summary>
        public CrmLocalizerManager()
        {
            if ( CrmLocManagerTrace.Sw.TraceVerbose || ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine("[V]CrmLocalizerManager Ctor BEG",(CrmLocManagerTrace.Sw.TraceVerbose ) ? CrmLocManagerTrace.Sw.Info :ModuleTraceSwitch.Sw.Info);
            if ( CrmLocManagerTrace.Sw.TraceVerbose || ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine("[V]CrmLocalizerManager Ctor END",(CrmLocManagerTrace.Sw.TraceVerbose) ? CrmLocManagerTrace.Sw.Info:ModuleTraceSwitch.Sw.Info);
        }

        public override string ExtendedResourcesGroup 
		{
            get
            {
                const string extgrp                             =   "CRMLOCALIZERMANAGER";
                return extgrp;
            }
		}

        public override void InitPortalModuleControl(ModuleSettingsDictionary bSettings)
        {
            PortalModuleInitializer =   new CrmLocalizerManagerSI(bSettings,this);
        }

        #endregion Ctor

        protected void Page_Load(object sender, EventArgs e)
        {
           if ( CrmLocManagerTrace.Sw.TraceVerbose || ModuleTraceSwitch.Sw.TraceVerbose )
               Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager Page_Load BEG IsPostBack: {0}, IsInAsyncPostBack: {1}, IsCallback: {2}",IsPostBack,IsInAsyncPostBack,Page.IsCallback ),( CrmLocManagerTrace.Sw.TraceVerbose ) ? CrmLocManagerTrace.Sw.Info :ModuleTraceSwitch.Sw.Info);
           if ( !IsPostBack && !Page.IsCallback )
           {
               ComboEntities.DataSource     =   GetAllEntities();
               ComboEntities.DataTextField  =   "displayName";
               ComboEntities.DataValueField =   "entityName";
               ComboEntities.DataBind();
               ComboEntities.Sort           =    RadComboBoxSort.Ascending;
               ComboEntities.SortItems();
               string AllStr                =   LocalizeHelper.Localize( LStr.All,"All");

               RadComboBoxItem it           =   new RadComboBoxItem(AllStr,"All");
               ComboEntities.Items.Insert(0,it);
               // Is it a language change request
               string ob                    =   Request.QueryString[strLocEntity];
               if ( CrmLocManagerTrace.Sw.TraceVerbose )
                   Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager Page_Load LocEntity: {0}",ob),CrmLocManagerTrace.Sw.Info);
               if ( !string.IsNullOrEmpty(ob) )
               {
                   RadComboBoxItem it1      =   ComboEntities.FindItemByValue(ob);
                   if ( it1 != null )
                       it                   =   it1;
               }
               it.Selected                  =   true;
               if (it.Value == "All" )
                        FieldsGrid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None;
               else    FieldsGrid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;

           }
           if ( CrmLocManagerTrace.Sw.TraceVerbose || ModuleTraceSwitch.Sw.TraceVerbose )
               Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager Page_Load END IsPostBack: {0}",IsPostBack),(CrmLocManagerTrace.Sw.TraceVerbose)? CrmLocManagerTrace.Sw.Info:ModuleTraceSwitch.Sw.Info);
         }

        #region Main methods

        void ComboEntities_SelectedIndexChanged(object o,RadComboBoxSelectedIndexChangedEventArgs e)
        {
            if ( CrmLocManagerTrace.Sw.TraceVerbose )
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager ComboEntities_SelectedIndexChanged BEG Text: {0}, Value: {1}.",e.Text,e.Value),CrmLocManagerTrace.Sw.Info);
            // Add New not available when displaying all entities
            if ( e.Value == "All" )
                    FieldsGrid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None;
            else    FieldsGrid.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
            FieldsGrid.DataSource   =   null;
            FieldsGrid.Rebind();
            LocalizeGrid.DataSource =   null;
            LocalizeGrid.Rebind();
            if ( CrmLocManagerTrace.Sw.TraceVerbose )
                Trace2.WriteLine("[V]CrmLocalizerManager ComboEntities_SelectedIndexChanged END.",CrmLocManagerTrace.Sw.Info);
        }

        #region FieldsGrid Handlers

        void FieldsGrid_NeedDataSource(object source,GridNeedDataSourceEventArgs e)
        {
            string entityName                       =   ComboEntities.SelectedValue;
            if ( CrmLocManagerTrace.Sw.TraceVerbose )
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager FieldsGrid_NeedDataSource BEG RebindReason: {0}, entityName: {1}.",e.RebindReason,entityName),CrmLocManagerTrace.Sw.Info);
            CRMFieldDescList SelVals                =   null;
            if ( entityName != "All" )
            {
                SelVals                             =   new CRMLocalizer(entityName).Vals;
            }
            else
            {
                SelVals                             =   new CRMLocalizer(PortalID).Vals;
            }
            FieldsGrid.DataSource                   =   SelVals.Values;
            if ( CrmLocManagerTrace.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]CrmLocalizerManager FieldsGrid_NeedDataSource END.",CrmLocManagerTrace.Sw.Info);
        }

        /// <summary>
        ///  We can't change FielName in update mode so disable the combobox if present
        /// </summary>
        protected void FieldsGrid_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem )
            {
                if (CrmLocManagerTrace.Sw.TraceVerbose)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager FieldsGrid_ItemCreated BEG Item: {0}, Type: {1}, IsInEditMode: {2}",
                        e.Item,e.Item.ItemType,e.Item.IsInEditMode),CrmLocManagerTrace.Sw.Info);
                GridEditableItem item                           =   (GridEditableItem)e.Item;
                if ( item.IsInEditMode )
                {
                    GridEditManager editMan                     =   item.EditManager;
                    GridTextBoxColumnEditor editor              =   (GridTextBoxColumnEditor)editMan.GetColumnEditor( "TypeName" );
                    if ( editor != null && editor.TextBoxControl != null )
                        editor.TextBoxControl.Enabled           =   false;
                    // We can't change TypeName in insert or update mode
                    // We can't change FielName in update mode
                    if ( !item.OwnerTableView.IsItemInserted )
                    {
                        GridDropDownListColumnEditor ed         =   (GridDropDownListColumnEditor)editMan.GetColumnEditor( "Fieldname" );
                        if ( ed != null && ed.ComboBoxControl != null )
                        {
                            if (CrmLocManagerTrace.Sw.TraceVerbose)
                                Trace2.WriteLine( "[V]CrmLocalizerManager FieldsGrid_ItemCreated ComboBoxControl disabled.",CrmLocManagerTrace.Sw.Info);
                            ed.ComboBoxControl.Enabled      =   false;
                        }
                    }
               }
            }
        }
        
        /// <summary>
        /// Bind the FieldName RadCombobox when in edit mode
        /// </summary>
        void FieldsGrid_ItemDataBound(object sender,GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem )
            {
                if (CrmLocManagerTrace.Sw.TraceVerbose)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager FieldsGrid_ItemDataBound BEG Item: {0}, Type: {1}, IsInEditMode: {2}",
                        e.Item,e.Item.ItemType,e.Item.IsInEditMode),CrmLocManagerTrace.Sw.Info);
                GridEditableItem item               =   (GridEditableItem)e.Item;
                string entName                      =   ComboEntities.SelectedValue;
                if ( item.IsInEditMode )
                {
                    bool binded                     =   false;
                    if (CrmLocManagerTrace.Sw.TraceVerbose)
                        Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager FieldsGrid_ItemDataBound DataItem: {0}",e.Item.DataItem.GetType()),CrmLocManagerTrace.Sw.Info);
                    CRMLocFieldDesc rw              =   null;
                    if ( !item.OwnerTableView.IsItemInserted )
                    {
                        rw                          =   (CRMLocFieldDesc)e.Item.DataItem;
                        entName                     =   rw.TypeName;
                    }
                    try
                    {  
                        GridEditManager editMan     =   item.EditManager;
                        // Set entityName when in insert Mode
                        GridTextBoxColumnEditor ed  =   (GridTextBoxColumnEditor)editMan.GetColumnEditor( "TypeName" );
                        if ( ed != null )
                            ed.TextBoxControl.Text  =   entName;
                        GridDropDownListColumnEditor editor =(GridDropDownListColumnEditor)editMan.GetColumnEditor( "Fieldname" );
                        //in case you have RadComboBox editor for the GridDropDownColumn (this is the default editor),         
                        //you will need to use ComboBoxControl below instead of DropDownListControl
                        //Then you can modify the list control as per your custom conventions
                        editor.DataSource           =   CRMLocalizer.CreateAttributesTable(Wrapper,entName);
                        editor.DataBind();
                        if (rw != null)
                        {
                            RadComboBoxItem it      =   editor.ComboBoxControl.Items.FindItemByValue(rw.Fieldname.ToString());
                            if (it != null)
                                it.Selected         =   true;
                        }
                        binded                      =   true;
                        if (CrmLocManagerTrace.Sw.TraceVerbose)
                            Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager FieldsGrid_ItemDataBound AttributeType Count: {0}",editor.ComboBoxControl.Items.Count),CrmLocManagerTrace.Sw.Info);
                    }
                    catch(Exception ex)
                    { 
                        if (CrmLocManagerTrace.Sw.TraceError)
                            Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[E]CrmLocalizerManager FieldsGrid_ItemDataBound ex: {0}",ex),CrmLocManagerTrace.Sw.Info);
                    }
                    if (CrmLocManagerTrace.Sw.TraceVerbose)
                        Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager FieldsGrid_ItemDataBound END binded: {0}",binded),CrmLocManagerTrace.Sw.Info);
                }
                else
                {
                    if ( e.Item.ItemType != GridItemType.Item && 
                        e.Item.ItemType != GridItemType.AlternatingItem )
                        return;
                    if ( !(e.Item.DataItem is CRMLocFieldDesc) )
                        return;
                    CRMLocFieldDesc rw              =   (CRMLocFieldDesc)e.Item.DataItem;
                    entName                         =   rw.TypeName;
                    EntityConfig conf               =   GetEntityConfig(entName);
                    InternalAttributeMetadata att   =   conf[rw.Fieldname];
                    string displayName              =   Wrapper.Util.ExtractAttributeFieldAsString(att, InternalAttributeFields.DisplayName);
                    item["Fieldname"].Text          =   displayName;
                    if (CrmLocManagerTrace.Sw.TraceVerbose)
                        Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager FieldsGrid_ItemDataBound Fieldname: {0}, displayName: {1}",rw.Fieldname,displayName),CrmLocManagerTrace.Sw.Info);
                }
            }
        }

        private void FieldsGrid_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (CrmLocManagerTrace.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager FieldsGrid_InsertCommand BEG e.Item : {0}", e.Item), CrmLocManagerTrace.Sw.Info);
            GridEditableItem editedItem =   e.Item as GridEditableItem;
            string FieldName            =   string.Empty;
            string TypeName             =   ComboEntities.SelectedValue;
            try
            {
                Hashtable newValues     =   new Hashtable();
                e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
                int Length              =   0;
                int DSize               =   0;
                foreach (DictionaryEntry entry in newValues)
                {
                    string Key          =   (string)entry.Key;
                    object ob           =   entry.Value;
                    if (ob != null)
                    {
                        if ( Key == "Fieldname" )
                            FieldName   =   (string)ob;
                        else if ( Key == "FieldLenght" )
                            Length      =   int.Parse(ob.ToString());
                        else if ( Key == "DisplaySize" )
                            DSize       =   int.Parse(ob.ToString());
                        if (CrmLocManagerTrace.Sw.TraceVerbose)
                            Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager FieldsGrid_InsertCommand inserting field: {0}, Value: {1}", entry.Key, entry.Value), CrmLocManagerTrace.Sw.Info);
                    }
                }
                EntityConfig conf       =   GetEntityConfig(TypeName);
                InternalAttributeMetadata att   =   conf[FieldName];
                int attType             =   Wrapper.Util.ExtractAttributeFieldAsInt(att,InternalAttributeFields.AttributeType);
                int Flags               =   Wrapper.Util.ExtractAttributeFieldAsInt(att,InternalAttributeFields.DisplayMask);
                // To check: where is att length ?
                if ( Length == 0 )
                    Length              =   ( attType == (int)AttributeInternalType.Memo ) ? Settings[LStr.CrmLocalizerManagerMemoLen].ToInt() : Settings[LStr.CrmLocalizerManagerTextLen].ToInt();
                if ( DSize == 0 )
                {
                    Unit USize          =   ( attType == (int)AttributeInternalType.Memo ) ? Settings[LStr.CrmLocalizerManagerMemoSize].ToUnit() : Settings[LStr.CrmLocalizerManagerTextSize].ToUnit();
                    if ( !USize.IsEmpty && (USize.Type == UnitType.Pixel ) )
                        DSize           =   (int)USize.Value;
                }
                if ( CrmLocManagerTrace.Sw.TraceVerbose )
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager FieldsGrid_InsertCommand adding FieldName: {0}.",FieldName),CrmLocManagerTrace.Sw.Info);
                fDB.UpdateFieldLocalizerDesc(0,PortalID,TypeName,FieldName,attType,Flags,Length,DSize);
                CRMLocalizer.ClearCache(PortalID,TypeName);
            }
            catch (Exception ex)
            {
                if (CrmLocManagerTrace.Sw.TraceError)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[E]CrmLocalizerManager FieldsGrid_InsertCommand ex: {0}", ex), CrmLocManagerTrace.Sw.Info);
                LbError.Text            =   LocalizeHelper.Localize( LStr.UnableInsertAtt,"Unable to insert Attribute.");
                e.Canceled              =   true;
                return;
            }
            string fmt                  =   LocalizeHelper.Localize( LStr.AttributeInserted,"Entity {0} Attribute {1} inserted");
            string msg                  =   string.Format(fmt,TypeName,FieldName);
            FieldsGrid.Controls.Add(new LiteralControl(msg));
            if (CrmLocManagerTrace.Sw.TraceVerbose)
                Trace2.WriteLine("[V]CrmLocalizerManager FieldsGrid_InsertCommand END.", CrmLocManagerTrace.Sw.Info);
        }
        
        protected void FieldsGrid_UpdateCommand(object source, GridCommandEventArgs e)
        {
            if (CrmLocManagerTrace.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager FieldsGrid_UpdateCommand BEG e.Item : {0}",e.Item),CrmLocManagerTrace.Sw.Info);
            GridEditableItem editedItem =   e.Item as GridEditableItem;
            int FieldId                 =   (int)editedItem.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["FieldId"];
            //Locate the changed row in the DataSource
            if (CrmLocManagerTrace.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager FieldsGrid_UpdateCommand FieldId: {0}",FieldId),CrmLocManagerTrace.Sw.Info);

            string FieldName            =   string.Empty;
            string TypeName             =   ComboEntities.SelectedValue;
            try
            {
                Hashtable newValues     =   new Hashtable();
                e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
                int Length              =   0;
                int DSize               =   0;
                foreach (DictionaryEntry entry in newValues)
                {
                    string Key          =   (string)entry.Key;
                    object ob           =   entry.Value;
                    if (ob != null)
                    {
                        if ( Key == "TypeName" )
                            TypeName    =   (string)ob;
                        if ( Key == "Fieldname" )
                            FieldName   =   (string)ob;
                        else if ( Key == "FieldLenght" )
                            Length      =   int.Parse(ob.ToString());
                        else if ( Key == "DisplaySize" )
                            DSize       =   int.Parse(ob.ToString());
                        if (CrmLocManagerTrace.Sw.TraceVerbose)
                            Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager FieldsGrid_UpdateCommand updating field: {0}, Value: {1}", entry.Key, entry.Value), CrmLocManagerTrace.Sw.Info);
                    }
                }

                if (CrmLocManagerTrace.Sw.TraceVerbose)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager FieldsGrid_UpdateCommand TypeName: {0}.",TypeName), CrmLocManagerTrace.Sw.Info);
                EntityConfig conf       =   GetEntityConfig(TypeName);
                InternalAttributeMetadata att   =   conf[FieldName];
                int attType             =   Wrapper.Util.ExtractAttributeFieldAsInt(att,InternalAttributeFields.AttributeType);
                int Flags               =   Wrapper.Util.ExtractAttributeFieldAsInt(att,InternalAttributeFields.DisplayMask);
                if ( Length == 0 )
                    Length              =   ( attType == (int)AttributeInternalType.Memo ) ? 0 : 2000;
                if ( DSize == 0 )
                    DSize               =   ( attType == (int)AttributeInternalType.Memo ) ? 300 : 600;
                if ( CrmLocManagerTrace.Sw.TraceVerbose )
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager FieldsGrid_UpdateCommand updating FieldName: {0}.",FieldName),CrmLocManagerTrace.Sw.Info);
                fDB.UpdateFieldLocalizerDesc(FieldId,PortalID,TypeName,FieldName,attType,Flags,Length,DSize);
                CRMLocalizer.ClearCache(PortalID,TypeName);
            }
            catch (Exception ex)
            {
                if (CrmLocManagerTrace.Sw.TraceError)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[E]CrmLocalizerManager FieldsGrid_UpdateCommand ex: {0}",ex),CrmLocManagerTrace.Sw.Info);
                FieldsGrid.Controls.Add(new LiteralControl("Unable to update Field. Reason: " + ex.Message));
                e.Canceled              =   true;
                return;
            }

            string msg                  =   string.Format("Entity {0}, Attribute {1} updated",TypeName,FieldName);
            FieldsGrid.Controls.Add(new LiteralControl(msg));
            if (CrmLocManagerTrace.Sw.TraceVerbose)
                Trace2.WriteLine( "[V]CrmLocalizerManager FieldsGrid_UpdateCommand END.",CrmLocManagerTrace.Sw.Info);
        }
        
        
        protected void FieldsGrid_DeleteCommand(object source, GridCommandEventArgs e)
        {
            if (CrmLocManagerTrace.Sw.TraceVerbose)
                Trace2.WriteLine( "[V]CrmLocalizerManager FieldsGrid_DeleteCommand BEG.",CrmLocManagerTrace.Sw.Info);
            int FieldId                 =   (int)(e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["FieldId"];
            string TypeName             =   (string)(e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["TypeName"];
            if (CrmLocManagerTrace.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager FieldsGrid_DeleteCommand FieldId: {0}.",FieldId),CrmLocManagerTrace.Sw.Info);
            try
            {
                fDB.DeleteFieldLocalizerDesc(FieldId);
                CRMLocalizer.ClearCache(PortalID,TypeName);
            }
            catch (Exception ex)
            {
                if (CrmLocManagerTrace.Sw.TraceError)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[E]CrmLocalizerManager FieldsGrid_DeleteCommand ex: {0}", ex), CrmLocManagerTrace.Sw.Info);
                string fmt              =   LocalizeHelper.Localize( LStr.UnableDeleteAtt,"Entity {0} Attribute {1} inserted");
                LbError.Text            =   string.Format(fmt,FieldId, ex);
                e.Canceled              =   true;
                return;
            }

            if (CrmLocManagerTrace.Sw.TraceVerbose)
                Trace2.WriteLine( "[V]CrmLocalizerManager FieldsGrid_DeleteCommand END.",CrmLocManagerTrace.Sw.Info);
        }

        #endregion FieldsGrid Handlers

        #region LocalizeGrid Handlers

        void LocalizeGrid_NeedDataSource(object source,GridNeedDataSourceEventArgs e)
        {
            string entityName                   =   ComboEntities.SelectedValue;
            if ( CrmLocManagerTrace.Sw.TraceVerbose )
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager LocalizeGrid_NeedDataSource BEG RebindReason: {0}, entityName: {1}.",e.RebindReason,entityName),CrmLocManagerTrace.Sw.Info);
            try
            {
                if ( entityName != "All" )
                {
                        LocalizeGrid.DataSource =   fDB.GetFieldLocalizerGlobalizedByEntityAll(entityName);
                    }
                else
                {
                        LocalizeGrid.DataSource =   fDB.GetFieldLocalizerGlobalizedByPortal(PortalID); 
                }
            }
            catch (Exception ex)
            {
                if ( CrmLocManagerTrace.Sw.TraceError )
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[E]CrmLocalizerManager LocalizeGrid_NeedDataSource ex: {0}",ex),CrmLocManagerTrace.Sw.Info);
                throw;
            }
            if ( CrmLocManagerTrace.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]CrmLocalizerManager LocalizeGrid_NeedDataSource END.",CrmLocManagerTrace.Sw.Info);
        }

        // Local flag
        bool LocalizeGridinEditMode   =   false; 

        /// <summary>
        ///  We invalidate the unnecessary edit item
        /// </summary>
        protected void LocalizeGrid_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem )
            {
                if (CrmLocManagerTrace.Sw.TraceVerbose)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager LocalizeGrid_ItemCreated BEG Item: {0}, Type: {1}, IsInEditMode: {2}",
                        e.Item,e.Item.ItemType,e.Item.IsInEditMode),CrmLocManagerTrace.Sw.Info);
                GridEditableItem item                       =   (GridEditableItem)e.Item;
                if ( item.IsInEditMode )
                {
                    if ( item.DataItem == null )
                        return;
                    DbDataRecord rw                         =   (DbDataRecord)item.DataItem;
                    string entName                          =   (string)rw["TypeName"];
                    EntityConfig conf                       =   GetEntityConfig(entName);
                    string Fieldname                        =   (string)rw["Fieldname"];
                    InternalAttributeMetadata att           =   conf[Fieldname];
                    AttributeInternalType attType           =   (AttributeInternalType)Wrapper.Util.ExtractAttributeFieldAsInt(att, InternalAttributeFields.AttributeType);
                    GridEditManager editMan                 =   item.EditManager;
                    if ( attType != AttributeInternalType.Memo )
                    {
                        item["LongValue"].Parent.Visible    =   false;
                    }
                    else
                    {
                        item["ShortValue"].Parent.Visible    =   false;
                    }
               }
            }
        }


        /// <summary>
        /// Bind the FieldName to DisplayName
        /// </summary>
        void LocalizeGrid_ItemDataBound(object sender,GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem )
            {
                if (CrmLocManagerTrace.Sw.TraceVerbose)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager LocalizeGrid_ItemDataBound BEG Item: {0}, Type: {1}, IsInEditMode: {2}",
                        e.Item,e.Item.ItemType,e.Item.IsInEditMode),CrmLocManagerTrace.Sw.Info);
                GridEditableItem item           =   (GridEditableItem)e.Item;
                if ( !item.IsInEditMode )
                {
                    if ( !(e.Item.DataItem is DbDataRecord) )
                        return;
                    DbDataRecord rw                 =   (DbDataRecord)e.Item.DataItem;
                    string entName                  =   (string)rw["TypeName"];
                    EntityConfig conf               =   GetEntityConfig(entName);
                    string Fieldname                =   (string)rw["Fieldname"];
                    InternalAttributeMetadata att   =   conf[Fieldname];
                    string displayName              =   Wrapper.Util.ExtractAttributeFieldAsString(att, InternalAttributeFields.DisplayName);
                    item["Fieldname"].Text          =   displayName;
                    if (CrmLocManagerTrace.Sw.TraceVerbose)
                        Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager LocalizeGrid_ItemDataBound Fieldname: {0}, displayName: {1}",Fieldname,displayName),CrmLocManagerTrace.Sw.Info);
                    Guid CrmId                      =   (Guid)rw["CrmId"];
                    if ( ( currentDyn == null ) || ( currentDyn.PrimaryKeyGuidValue != CrmId ) )
                    {
                        currentDyn                  =    new DynEntity(Wrapper,entName,CrmId);
                        if ( !currentDyn.Retrieve() )
                        {
                            if ( CrmLocManagerTrace.Sw.TraceVerbose )
                                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager LocalizeGrid_ItemDataBound NOT FOUND entityName: {0}, CrmId: {1}",entName,CrmId),CrmLocManagerTrace.Sw.Info);
                            return;
                        }
                    }
                    if ( ( currentDyn != null ) && ( currentDyn.HasPrimaryField ) )
                        item["CrmId"].Text          =   currentDyn.PrimaryFieldStringValue;
                }
                else 
                {
                    LocalizeGridinEditMode          =   true;
                    GridHTMLEditorColumnEditor editor = (GridHTMLEditorColumnEditor)item.EditManager.GetColumnEditor("LongValue");  
                    RadEditor rEdt                  =   editor.Editor; 
             
                    string[] SupportedLanguages     =   PortalSettings.SpellCheckerCultures;
                    foreach(string dicLang in SupportedLanguages)
                            rEdt.Languages.Add(new SpellCheckerLanguage(dicLang,new CultureInfo(dicLang).DisplayName));
                    EditorToolGroup main            =   new EditorToolGroup();  
                    rEdt.Tools.Add(main);  
                    main.Tools.Add(new EditorSeparator());  
                    EditorTool spellCheck           =   new EditorTool();  
                    spellCheck.Name                 =   "AjaxSpellCheck";  
                    spellCheck.ShortCut             =   "CTRL+L";  
                    main.Tools.Add(spellCheck);  
                    main.Tools.Add(new EditorSeparator());  
                    EditorTool FindReplace          =   new EditorTool();  
                    FindReplace.Name                =   "FindAndReplace";  
                    FindReplace.ShortCut            =   "CTRL+F";  
                    main.Tools.Add(FindReplace);  
                    main.Tools.Add(new EditorSeparator());  
                    EditorTool Cut                  =   new EditorTool();  
                    Cut.Name                        =   "Cut";  
                    Cut.ShortCut                    =   "CTRL+X";  
                    main.Tools.Add(Cut);  
                    EditorTool Copy                 =   new EditorTool();  
                    Copy.Name                       =   "Copy";  
                    Copy.ShortCut                   =   "CTRL+C";  
                    main.Tools.Add(Copy);  
                    EditorTool Paste                =   new EditorTool();  
                    Paste.Name                      =   "Paste";  
                    Paste.ShortCut                  =   "CTRL+V";  
                    main.Tools.Add(Paste);  
                    main.Tools.Add(new EditorSeparator());  
                    EditorTool Undo                 =   new EditorTool();  
                    Undo.Name                       =   "Undo";  
                    Undo.ShortCut                   =   "CTRL+Z";  
                    main.Tools.Add(Undo);  
                    EditorTool Redo                 =   new EditorTool();  
                    Redo.Name                       =   "Redo";  
                    Redo.ShortCut                   =   "CTRL+Y";  
                    main.Tools.Add(Redo);  
                    main.Tools.Add(new EditorSeparator());  
                }
            }
        }

        /// <summary>
        /// Update Short or Long Value depending on settings
        /// </summary>
        protected void LocalizeGrid_UpdateCommand(object source, GridCommandEventArgs e)
        {
            if (CrmLocManagerTrace.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager LocalizeGrid_UpdateCommand BEG e.Item : {0}",e.Item),CrmLocManagerTrace.Sw.Info);
            GridEditableItem editedItem     =   e.Item as GridEditableItem;

            Hashtable newValues         =   new Hashtable();
            //The GridTableView will fill the values from all editable columns in the hash
            e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
            string TypeName             =   string.Empty;
            //string Fieldname            =   string.Empty;
            Guid CrmId                  =   Guid.Empty;
            int FieldId                 =   0;
            try
            {
                TypeName                =   (string)editedItem.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["TypeName"];
                CrmId                   =   (Guid)editedItem.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CrmId"];
                FieldId                 =   (int)editedItem.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["FieldId"];
                if (CrmLocManagerTrace.Sw.TraceVerbose)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager LocalizeGrid_UpdateCommand CrmId: {0}, FieldId: {1}.",CrmId,FieldId),CrmLocManagerTrace.Sw.Info);
                string shortValue       =   (string)newValues["ShortValue"];
                if ( shortValue == null )
                    shortValue          =   string.Empty;
                string longValue        =   (string)newValues["LongValue"];
                if ( longValue == null )
                    longValue           =   string.Empty;
                if (CrmLocManagerTrace.Sw.TraceVerbose)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager LocalizeGrid_UpdateCommand shortValue: {0}, longValue: {1}.",shortValue,longValue),CrmLocManagerTrace.Sw.Info);
                fDB.UpdateFieldLocalizerGlobalized(TypeName,CrmId,FieldId,shortValue,longValue);
            }
            catch (Exception ex)
            {
                if (CrmLocManagerTrace.Sw.TraceError)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[E]CrmLocalizerManager LocalizeGrid_UpdateCommand CrmId: {0}, FieldId: {1}, ex: {2}",CrmId,FieldId,ex),CrmLocManagerTrace.Sw.Info);
                string msg              =   LocalizeHelper.Localize( LStr.UnableUpdateLoc,"Unable to update value.");
                LocalizeGrid.Controls.Add(new LiteralControl(msg));
                e.Canceled              =   true;
            }
            LocalizeGridinEditMode      =   false;
            string fmt                  =   LocalizeHelper.Localize( LStr.LocUpdated,"{0} updated");
            fmt                         =   string.Format(fmt,TypeName);
            LocalizeGrid.Controls.Add(new LiteralControl(fmt));
            if (CrmLocManagerTrace.Sw.TraceVerbose)
                Trace2.WriteLine( "[V]CrmLocalizerManager LocalizeGrid_UpdateCommand END.",CrmLocManagerTrace.Sw.Info);
        }
        
        void LocalizeGrid_DeleteCommand(object source,GridCommandEventArgs e)
        {
            if (CrmLocManagerTrace.Sw.TraceVerbose)
                Trace2.WriteLine( "[V]CrmLocalizerManager LocalizeGrid_DeleteCommand BEG.",CrmLocManagerTrace.Sw.Info);
            string TypeName         =   (string)(e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["TypeName"];
            Guid CrmId              =   (Guid)(e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CrmId"];
            int FieldId             =   (int)(e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["FieldId"];
            if (CrmLocManagerTrace.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager LocalizeGrid_DeleteCommand CrmId: {0}, FieldId: {1}.",CrmId,FieldId),CrmLocManagerTrace.Sw.Info);
            try
            {
                fDB.DeleteFieldLocalizerGlobalized(TypeName,CrmId,FieldId);
            }
            catch (Exception ex)
            {
                if (CrmLocManagerTrace.Sw.TraceError)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[E]CrmLocalizerManager LocalizeGrid_DeleteCommand ex: {0}", ex), CrmLocManagerTrace.Sw.Info);
                string fmt          =   LocalizeHelper.Localize( LStr.UnableDeleteLoc,"Unable to delete {0}:{1}:{2}.");
                LbError.Text        = string.Format(fmt,TypeName,CrmId,FieldId);
                e.Canceled          =   true;
            }

            if (CrmLocManagerTrace.Sw.TraceVerbose)
                Trace2.WriteLine( "[V]CrmLocalizerManager LocalizeGrid_DeleteCommand END.",CrmLocManagerTrace.Sw.Info);
        }

        /// <summary>
        /// Hide Group panel when in edit mode
        /// </summary>
        private void LocalizeGrid_PreRender(object sender, System.EventArgs e)
        {
          if( LocalizeGridinEditMode )
                LocalizeGrid.ShowGroupPanel     =   false; 
            else LocalizeGrid.ShowGroupPanel    =   true; 
        }

        #endregion LocalizeGrid Handlers

        void LangChooser2_ChangeLanguage(object sender,LangChooserEventArgs e)
        {
            string entityName   =   ComboEntities.SelectedValue;
            string str          =   LangChooser2.GetLangUrl(e.CultureItem.UICulture.Name);
            str                 =   LangChooser2.RemoveQueryString(str,strLocEntity);
            string Url          =   string.Format("{0}&{1}={2}",str,strLocEntity,entityName); 
            if (CrmLocManagerTrace.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]CrmLocalizerManager LangChooser2_ChangeLanguage url: '{0}'",Url),CrmLocManagerTrace.Sw.Info);
			ADNPage.Redirect(Url,true);
        }

        #endregion Main methods


        #region Std Overrides

		public override void Page_PreInit(object sender, EventArgs e)
        {
            if ( CrmLocManagerTrace.Sw.TraceVerbose || ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]CrmLocalizerManager Page_PreInit BEG.",(CrmLocManagerTrace.Sw.TraceVerbose) ? CrmLocManagerTrace.Sw.Info:ModuleTraceSwitch.Sw.Info);
            base.Page_PreInit(sender, e);
            LangChooser2.Type                   =   LangChooserType.DropDownList;
            LangChooser2.ChangeLanguageAction   =   LangChooserAction.CallDelegate;

            if ( CrmLocManagerTrace.Sw.TraceVerbose || ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]CrmLocalizerManager Page_PreInit END.",(CrmLocManagerTrace.Sw.TraceVerbose) ? CrmLocManagerTrace.Sw.Info:ModuleTraceSwitch.Sw.Info);
		}
		

        override protected void OnInit(EventArgs e)
        {
            if ( CrmLocManagerTrace.Sw.TraceVerbose || ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]CrmLocalizerManager OnInit BEG.",(CrmLocManagerTrace.Sw.TraceVerbose) ? CrmLocManagerTrace.Sw.Info:ModuleTraceSwitch.Sw.Info);
            InitializeComponent();
            base.OnInit(e);
            if ( CrmLocManagerTrace.Sw.TraceVerbose || ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]CrmLocalizerManager OnInit END.",(CrmLocManagerTrace.Sw.TraceVerbose) ? CrmLocManagerTrace.Sw.Info:ModuleTraceSwitch.Sw.Info);
        }
 

        private void InitializeComponent()
        {
            Load                                +=  new System.EventHandler(this.Page_Load);
            LangChooser2.ChangeLanguage         +=  new LangChooserEventHandler(LangChooser2_ChangeLanguage);
            ComboEntities.SelectedIndexChanged  +=  new RadComboBoxSelectedIndexChangedEventHandler(ComboEntities_SelectedIndexChanged);

            FieldsGrid.NeedDataSource           +=  new GridNeedDataSourceEventHandler(FieldsGrid_NeedDataSource);
            FieldsGrid.ItemCreated              +=  new GridItemEventHandler(FieldsGrid_ItemCreated);
            FieldsGrid.ItemDataBound            +=  new GridItemEventHandler(FieldsGrid_ItemDataBound);
            FieldsGrid.InsertCommand            +=  new GridCommandEventHandler(FieldsGrid_InsertCommand);
            FieldsGrid.UpdateCommand            +=  new GridCommandEventHandler(FieldsGrid_UpdateCommand);
            FieldsGrid.DeleteCommand            +=  new GridCommandEventHandler(FieldsGrid_DeleteCommand);

            LocalizeGrid.NeedDataSource         +=  new GridNeedDataSourceEventHandler(LocalizeGrid_NeedDataSource);
            LocalizeGrid.ItemCreated            +=  new GridItemEventHandler(LocalizeGrid_ItemCreated);
            LocalizeGrid.ItemDataBound          +=  new GridItemEventHandler(LocalizeGrid_ItemDataBound);
            LocalizeGrid.UpdateCommand          +=  new GridCommandEventHandler(LocalizeGrid_UpdateCommand);
            LocalizeGrid.DeleteCommand          +=  new GridCommandEventHandler(LocalizeGrid_DeleteCommand);
            LocalizeGrid.PreRender              +=  new EventHandler(LocalizeGrid_PreRender);
        }

        #endregion
        
    }
}